@extends('layouts.header')
@section('content')
	<h4><a href="{{ route('show_topic',['sub'=>$post->subwroteit]) }} " title="Go back">Return to {{$post->subwroteit}}</a></h4>
	<h2>{{ $post->title }} by {{$post->by_user}}</h2>
	<h3>{{ $post->content }} </h3>
	<hr/>
	<br />

    <form action="{{ route('store_new_comment') }}" method="POST" style="text-align: center;">
        {{ csrf_field() }}

		@if (Auth::check())
			<div class="form-group">
				<label for="content">Content: </label><textarea rows="8" style="width: 1218px;" name="content" class="input">{{ old('content')}}</textarea> <br /><br />
			</div>

			<div class="form-group">
				<input type="hidden" name="sub" value="{{ $post->subwroteit }}">
				<input type="hidden" name="postID" value="{{ $post->post_id_string }}">
				<button type="submit" class='btn btn-primary'>Publish</button>
        	</div>
		@else
			<div class="form-group">
				<label for="content">Content: </label><textarea rows="8" style="width: 1218px;" name="content" class="input" disabled>{{ old('content')}}</textarea> <br /><br />
			</div>

			<div class="form-group">
				<input type="hidden" name="sub" value="{{ $post->subwroteit }}">
				<input type="hidden" name="postID" value="{{ $post->post_id_string }}">
				<button type="submit" class='btn btn-primary' disabled>Publish</button>
        	</div>
		@endif
    </form>





	@foreach($comments as $comment)
		<h5> {{ $comment->userName }} at {{ ($comment->created_at) }} </h5>
		<h3 style="position:relative;top:-15px">{{ $comment->content }}<h3>

		@if(!$not_moderator && Auth::check())
			<form action="{{ route('delete_comment')}}" method="POST">
			{{ csrf_field() }}
				<input type="hidden" name ="id" value="{{ $comment->id }}">
				<input type="hidden" name ="subwroteID" value="{{ $comment->subwroteitID }}">
				<input type="hidden" name ="postID" value="{{ $comment->postID }}">
				<input type="submit" value="Delete comment" class="pull-right btn btn-success" name="submitBtn" onclick="this.disabled=true;this.form.submit();">
			</form><br>
		@endif
	@endforeach
	{{ $comments->links() }}


@endsection()
